<?php 
ob_start();
session_start();

error_reporting(0);

ini_set('soap.wsdl_cache_enabled', 0);

// 指定允许其他域名访问
header("Access-Control-Allow-Origin: *");
// 响应类型
header("Access-Control-Allow-Methods: POST");
// 响应头设置
header("Access-Control-Allow-Headers: x-requested-with,content-type");

header("content-type: text/html;charset=utf-8");

define('WSSdkSource_PLATSOURCEPATH', dirname(dirname(dirname(__FILE__))).'/nmi/dbserver/PlatConnParam.ini');

$response = new stdClass();
$response->utc = time();


$request = null;
if (array_key_exists('QUERY_STRING', $_SERVER))
{
	$request = trim(rawurldecode($_SERVER['QUERY_STRING']));
}
if (empty($request))
{
	$request = trim(rawurldecode(file_get_contents("php://input")));
}

if (!empty($request))
{
	// 解析请求消息体，转为stdClass对象
	$request = json_decode($request);
	if (is_null($request) 
		|| (strcasecmp(PHP_VERSION, '5.3.0') >= 0 && json_last_error() != JSON_ERROR_NONE)
		|| empty($request)
		|| empty($request->action)) 
	{
		// 解析出错，	请求格式不正确
	}
}
else
{
	// 请求消息体为空
}

// 读取配置文件
$platfromWSDLPath = '';
if (file_exists(WSSdkSource_PLATSOURCEPATH))
{
    $contents = file_get_contents(WSSdkSource_PLATSOURCEPATH);

    $ini_nodes = explode("\r\n", $contents);

    foreach ($ini_nodes as $item)
    {
        list($key, $value) = preg_split("/\\=/", $item);
            
        if (isset($key))
        {
            switch ($key)
            {
                case 'SOAP_PATH':
                    $platfromWSDLPath = $value;
                    break;
                case 'username':
                    break;
                case 'epid':
                    break;
                case 'password':
                    break;
            }
        }
    }
}

//$soapActionURL = $platfromWSDLPath;
$soapActionURL = 'http://127.0.0.1:2580/GSoapWebserviceSDK/service/sdk.wsdl';
$soapClient = NULL;

$soapClient = new SoapClient($soapActionURL);

$result = NULL;
$action = $request->action;
$content = $request->content;

$param = array(
    'action' => $action, 
    'content' => $content
);

$param = json_encode($param);

$result = $soapClient->getRequest(array('request' => $param));

$result = $result->response;

$result = json_decode($result);

$response->errorCode = $result->errorCode;
$response->action = $result->action;
$response->content = $result->content;

echo json_encode($response);

ob_end_flush();
exit();
?>